<template>
  <!-- 驾驶员审核 -->
  <div class="search">
    <Card>
      <Row @keydown.enter.native="handleSearch">
        <Form
          ref="searchForm"
          :model="searchForm"
          inline
          :label-width="70"
          class="search-form"
        >
          <FormItem label="登录账号" prop="mobile">
            <Input
              type="text"
              v-model="searchForm.mobile"
              placeholder="请输入手机号"
              clearable
              style="width: 180px"
            />
          </FormItem>
          <FormItem label="用户姓名" prop="name">
            <Input
              type="text"
              v-model="searchForm.name"
              placeholder="请输入用户姓名"
              clearable
              style="width: 180px"
            />
          </FormItem>
          <span class="br" style="margin-left: 35px">
            <Button @click="handleSearch" type="primary" icon="ios-search"
              >搜索</Button
            >
            <Button @click="handleReset">重置</Button>
            <Button @click="getDataList" icon="md-refresh">刷新</Button>
          </span>
        </Form>
      </Row>
      <!--  -->
      <Row>
        <Table
          :loading="loading"
          border
          :columns="columns"
          :data="data"
          ref="table"
          sortable="custom"
          class="table"
          @on-sort-change="changeSort"
          @on-selection-change="changeSelect"
        ></Table>
      </Row>
      <Row type="flex" justify="end" class="page">
        <Page
          transfer
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>

    <Drawer
      title="驾驶员认证信息"
      :mask-closable="false"
      v-model="driverVisible"
      width="710"
    >
      <div class="demo-spin-article">
        <Tabs @on-click="driverTabs" v-model="driverTabPane">
          <TabPane label="身份证" name="name1">
            <div style="width: 100%; height: 15px"></div>
            <Form
              :model="driverData"
              :rules="RealAuthentication"
              ref="driverData"
              :label-width="150"
              inline
            >
              <div style="display: flex">
                <div style="margin-left: -100px">
                  <FormItem label="姓名" prop="name">
                    <Input
                      style="width: 275px"
                      placeholder="请输入姓名"
                      v-model="driverData.name"
                      clearable
                    />
                  </FormItem>
                </div>
                <div>
                  <FormItem
                    style="margin-left: -60px"
                    label="身份证号"
                    prop="num"
                  >
                    <Input
                      style="width: 220px"
                      placeholder="请输入身份证号"
                      v-model="driverData.num"
                      clearable
                    />
                  </FormItem>
                </div>
              </div>

              <FormItem
                style="margin-left: -70px"
                label="出生日期"
                prop="birth"
              >
                <DatePicker
                  transfer
                  type="date"
                  style="width: 245px"
                  format="yyyyMMdd"
                  placeholder="请选择出生日期"
                  :value="driverData.birth"
                  @on-change="driverDataBirth"
                ></DatePicker>
              </FormItem>
              <FormItem label="性别" prop="sex" style="margin-left: -88px">
                <Input
                  style="width: 250px"
                  placeholder="请输入性别"
                  v-model="driverData.sex"
                  clearable
                />
              </FormItem>
              <FormItem label="身份证有效开始日期" prop="startDate">
                <DatePicker
                  transfer
                  type="date"
                  style="width: 175px"
                  format="yyyyMMdd"
                  placeholder="请选择身份证有效开始日期"
                  :value="driverData.startDate"
                  @on-change="driverDataStartDate"
                ></DatePicker>
              </FormItem>
              <FormItem
                style="margin-left: 10px"
                label="身份证有效结束日期"
                prop="endDate"
              >
                <DatePicker
                  transfer
                  type="date"
                  style="width: 155px"
                  format="yyyyMMdd"
                  placeholder="请选择身份证有效结束日期"
                  :value="driverData.endDate"
                  @on-change="driverDataEndDate"
                ></DatePicker>
              </FormItem>
              <FormItem
                label="车主电话"
                style="margin-left: -68px"
                prop="contactPhone"
              >
                <Input
                  style="width: 244px"
                  placeholder="请输入车主电话"
                  v-model="driverData.contactPhone"
                  clearable
                />
              </FormItem>

              <Row style="margin-left: 8px">
                <Col span="8">
                  <div
                    v-if="idCardFontPicFileUrl"
                    style="
                      width: 148px;
                      height: 92px;
                      line-height: 75px;
                      margin-bottom: 8px;
                    "
                  >
                    <div class="demo-upload-list-driver">
                      <img
                        v-if="idCardFontPicFileUrl != ''"
                        style="width: 58px"
                        height="100px"
                        :src="idCardFontPicFileUrl"
                      />
                      <img
                        v-else
                        style="width: 58px"
                        height="100px"
                        src="@/assets/vehicleAtes/owner1.png"
                      />
                      <div
                        v-if="idCardFontPicFileUrl != ''"
                        class="demo-upload-list-driver-cover"
                      >
                        <Icon
                          type="ios-eye-outline"
                          @click.stop="showPic(idCardFontPicFileUrl)"
                        ></Icon>
                        <Icon
                          type="ios-trash-outline"
                          @click.stop="handleRemove(idCardFontPicFileUrl, 1)"
                        ></Icon>
                      </div>
                    </div>
                  </div>
                  <Upload
                    class="Upload-border"
                    v-else
                    :on-progress="FrontIDCard"
                    :beforeUpload="beforeUpload"
                    ref="fontUpload"
                    :show-upload-list="false"
                    :on-success="cardFontHandleSuccess"
                    :format="['jpg', 'jpeg', 'png']"
                    :on-format-error="handleFormatError"
                    :headers="header"
                    :data="{
                      fileType: 'IDCARD_FONT_PIC',
                      userId: form.userId,
                    }"
                    type="drag"
                    :action="uploadIdCardPic"
                    style="display: inline-block; width: 148px"
                  >
                    <div style="width: 148px; height: 92px; line-height: 75px">
                      <div class="demo-upload-list-driver">
                        <img
                          v-if="idCardFontPicFileUrl != ''"
                          style="width: 58px"
                          height="100px"
                          :src="idCardFontPicFileUrl"
                        />
                        <img
                          v-else
                          style="width: 58px"
                          height="100px"
                          src="@/assets/vehicleAtes/owner1.png"
                        />
                        <div
                          v-if="idCardFontPicFileUrl != ''"
                          class="demo-upload-list-driver-cover"
                        >
                          <Icon
                            type="ios-eye-outline"
                            @click.stop="showPic(idCardFontPicFileUrl)"
                          ></Icon>
                          <Icon
                            type="ios-trash-outline"
                            @click.stop="handleRemove(idCardFontPicFileUrl, 1)"
                          ></Icon>
                        </div>
                      </div>
                    </div>
                  </Upload>
                  <div class="demo-uploadcss-drivre">
                    <template>
                      <Progress
                        v-if="FrontIDCardTrue"
                        text-inside
                        :percent="load"
                        :stroke-width="3"
                      ></Progress>
                    </template>
                  </div>
                  <div style="margin-top: 8px" class="check">
                    <span class="check_font">身份证正面</span>
                  </div>
                </Col>
                <Col span="8">
                  <div
                    v-if="idCardBackPicFileUrl"
                    style="
                      width: 148px;
                      height: 92px;
                      line-height: 75px;
                      margin-bottom: 8px;
                    "
                  >
                    <div class="demo-upload-list-driver">
                      <img
                        v-if="idCardBackPicFileUrl != ''"
                        style="width: 58px"
                        height="100px"
                        :src="idCardBackPicFileUrl"
                      />
                      <img
                        v-else
                        style="width: 58px"
                        height="100px"
                        src="@/assets/vehicleAtes/owner2.png"
                      />
                      <div
                        v-if="idCardBackPicFileUrl != ''"
                        class="demo-upload-list-driver-cover"
                      >
                        <Icon
                          type="ios-eye-outline"
                          @click.stop="showPic(idCardBackPicFileUrl)"
                        ></Icon>
                        <Icon
                          type="ios-trash-outline"
                          @click.stop="handleRemove(idCardBackPicFileUrl, 2)"
                        ></Icon>
                      </div>
                    </div>
                  </div>
                  <Upload
                    class="Upload-border"
                    v-else
                    :on-progress="ReverseSideIDCard"
                    :beforeUpload="beforeUpload"
                    ref="backUpload"
                    :show-upload-list="false"
                    :on-success="cardBackHandleSuccess"
                    :before-upload="handleBeforeUpload"
                    :format="['jpg', 'jpeg', 'png']"
                    :on-format-error="handleFormatError"
                    type="drag"
                    :default-file-list="idCardBackPicFileList"
                    :headers="header"
                    :data="{
                      fileType: 'IDCARD_BACK_PIC',
                      userId: form.userId,
                    }"
                    :action="uploadIdCardPic"
                    style="display: inline-block; width: 148px"
                  >
                    <div style="width: 148px; height: 92px; line-height: 75px">
                      <div class="demo-upload-list-driver">
                        <img
                          v-if="idCardBackPicFileUrl != ''"
                          style="width: 58px"
                          height="100px"
                          :src="idCardBackPicFileUrl"
                        />
                        <img
                          v-else
                          style="width: 58px"
                          height="100px"
                          src="@/assets/vehicleAtes/owner2.png"
                        />
                        <div
                          v-if="idCardBackPicFileUrl != ''"
                          class="demo-upload-list-driver-cover"
                        >
                          <Icon
                            type="ios-eye-outline"
                            @click.stop="showPic(idCardBackPicFileUrl)"
                          ></Icon>
                          <Icon
                            type="ios-trash-outline"
                            @click.stop="handleRemove(idCardBackPicFileUrl, 2)"
                          ></Icon>
                        </div>
                      </div>
                    </div>
                  </Upload>
                  <div class="demo-uploadcss-drivre">
                    <template>
                      <Progress
                        v-if="ReverseSideIDCardTrue"
                        text-inside
                        :percent="load"
                        :stroke-width="3"
                      ></Progress>
                    </template>
                  </div>
                  <div style="margin-top: 8px" class="check">
                    <span class="check_font">身份证背面 </span>
                  </div>
                </Col>
              </Row>
            </Form>
          </TabPane>
          <TabPane label="驾驶证/资格证" name="name2">
            <div style="width: 100%; height: 15px"></div>
            <Form
              :model="driverData2"
              :rules="RealAuthentication2"
              ref="driverData2"
              :label-width="150"
              inline
            >
              <div style="display: flex">
                <div style="margin-left: -55px">
                  <FormItem label="驾驶证编号" prop="licenseNum">
                    <Input
                      style="width: 230px"
                      placeholder="请输入驾驶证编号"
                      v-model="driverData2.licenseNum"
                      clearable
                    />
                  </FormItem>
                </div>
                <div>
                  <FormItem
                    style="margin-left: -25px"
                    label="驾驶证发证机关"
                    prop="issuingOrganizations"
                  >
                    <Input
                      style="width: 200px"
                      placeholder="请输入驾驶证发证机关"
                      v-model="driverData2.issuingOrganizations"
                      clearable
                    />
                  </FormItem>
                </div>
              </div>
              <FormItem
                style="margin-left: -40px"
                label="初次领证日期"
                prop="issueDate"
              >
                <DatePicker
                  transfer
                  type="date"
                  style="width: 215px"
                  format="yyyyMMdd"
                  placeholder="请选择初次领证日期"
                  :value="driverData2.issueDate"
                  @on-change="driverDataIssueDate"
                ></DatePicker>
              </FormItem>
              <FormItem
                style="margin-left: -65px"
                label="准驾车型"
                prop="driverType"
              >
                <Input
                  style="width: 240px"
                  placeholder="请输入准驾车型"
                  v-model="driverData2.driverType"
                  clearable
                />
              </FormItem>

              <Row style="margin-left: 10px">
                <Col span="8">
                  <div
                    v-if="driverFontPicFileUrl"
                    style="
                      width: 148px;
                      height: 92px;
                      line-height: 75px;
                      margin-bottom: 8px;
                    "
                  >
                    <div class="demo-upload-list-driver">
                      <img
                        v-if="driverFontPicFileUrl != ''"
                        style="width: 58px"
                        height="100px"
                        :src="driverFontPicFileUrl"
                      />
                      <img
                        v-else
                        style="width: 58px"
                        height="100px"
                        src="@/assets/vehicleAtes/drier3.png"
                      />
                      <div
                        v-if="driverFontPicFileUrl != ''"
                        class="demo-upload-list-driver-cover"
                      >
                        <Icon
                          type="ios-eye-outline"
                          @click.stop="showPic(driverFontPicFileUrl)"
                        ></Icon>
                        <Icon
                          type="ios-trash-outline"
                          @click.stop="handleRemove(driverFontPicFileUrl, 3)"
                        ></Icon>
                      </div>
                    </div>
                  </div>
                  <Upload
                    class="Upload-border"
                    v-else
                    :on-progress="DriverLicense"
                    :beforeUpload="beforeUpload"
                    ref="fontUpload"
                    :show-upload-list="false"
                    :on-success="driverFontHandleSuccess"
                    :format="['jpg', 'jpeg', 'png']"
                    :on-format-error="handleFormatError"
                    :headers="header"
                    :data="{
                      fileType: 'DRIVER_FONT_PIC',
                      userId: form.userId,
                    }"
                    type="drag"
                    :action="upLoadDriverLicense"
                    style="display: inline-block; width: 148px"
                  >
                    <div style="width: 148px; height: 92px; line-height: 75px">
                      <div class="demo-upload-list-driver">
                        <img
                          v-if="driverFontPicFileUrl != ''"
                          style="width: 58px"
                          height="100px"
                          :src="driverFontPicFileUrl"
                        />
                        <img
                          v-else
                          style="width: 58px"
                          height="100px"
                          src="@/assets/vehicleAtes/drier3.png"
                        />
                        <div
                          v-if="driverFontPicFileUrl != ''"
                          class="demo-upload-list-driver-cover"
                        >
                          <Icon
                            type="ios-eye-outline"
                            @click.stop="showPic(driverFontPicFileUrl)"
                          ></Icon>
                          <Icon
                            type="ios-trash-outline"
                            @click.stop="handleRemove(driverFontPicFileUrl, 3)"
                          ></Icon>
                        </div>
                      </div>
                    </div>
                  </Upload>
                  <div class="demo-uploadcss-drivre">
                    <template>
                      <Progress
                        v-if="DriverLicenseTrue"
                        text-inside
                        :percent="load"
                        :stroke-width="3"
                      ></Progress>
                    </template>
                  </div>

                  <div style="margin-top: 8px" class="check">
                    <span class="check_font">驾照主页</span>
                  </div>
                </Col>

                <Col span="8" style="margin-left: 12px">
                  <div
                    v-if="workLicensePicFileUrl"
                    style="
                      width: 148px;
                      height: 92px;
                      line-height: 75px;
                      margin-bottom: 8px;
                    "
                  >
                    <div class="demo-upload-list-driver">
                      <img
                        v-if="workLicensePicFileUrl != ''"
                        style="width: 58px"
                        height="100px"
                        :src="workLicensePicFileUrl"
                      />
                      <img
                        v-else
                        style="width: 58px"
                        height="100px"
                        src="@/assets/vehicleAtes/owner5.png"
                      />
                      <div
                        v-if="workLicensePicFileUrl != ''"
                        class="demo-upload-list-driver-cover"
                      >
                        <Icon
                          type="ios-eye-outline"
                          @click.stop="showPic(workLicensePicFileUrl)"
                        ></Icon>
                        <Icon
                          type="ios-trash-outline"
                          @click.stop="handleRemove(workLicensePicFileUrl, 5)"
                        ></Icon>
                      </div>
                    </div>
                  </div>
                  <Upload
                    class="Upload-border"
                    v-else
                    :on-progress="QualificationCertificate"
                    :beforeUpload="beforeUpload"
                    ref="companyUpload"
                    :show-upload-list="false"
                    :on-success="workLicenesSuccess"
                    :format="['jpg', 'jpeg', 'png']"
                    :on-format-error="handleFormatError"
                    :headers="header"
                    :data="{
                      fileType: 'ROAD_OPERATION_PERMIT',
                      userId: form.userId,
                    }"
                    type="drag"
                    :action="upLoadDriverLicense"
                    style="display: inline-block; width: 148px"
                  >
                    <div style="width: 148px; height: 92px; line-height: 75px">
                      <div class="demo-upload-list-driver">
                        <img
                          v-if="workLicensePicFileUrl != ''"
                          style="width: 58px"
                          height="100px"
                          :src="workLicensePicFileUrl"
                        />
                        <img
                          v-else
                          style="width: 58px"
                          height="100px"
                          src="@/assets/vehicleAtes/owner5.png"
                        />
                        <div
                          v-if="workLicensePicFileUrl != ''"
                          class="demo-upload-list-driver-cover"
                        >
                          <Icon
                            type="ios-eye-outline"
                            @click.stop="showPic(workLicensePicFileUrl)"
                          ></Icon>
                          <Icon
                            type="ios-trash-outline"
                            @click.stop="handleRemove(workLicensePicFileUrl, 5)"
                          ></Icon>
                        </div>
                      </div>
                    </div>
                  </Upload>
                  <div class="demo-uploadcss-drivre">
                    <template>
                      <Progress
                        v-if="QualificationTrue"
                        text-inside
                        :percent="load"
                        :stroke-width="3"
                      ></Progress>
                    </template>
                  </div>
                  <div style="margin-top: 8px" class="check">
                    <span class="check_font">从业资格证</span>
                  </div>
                </Col>
              </Row>
            </Form>
            <div>
              <Button
                type="warning"
                style="margin-top: 22px"
                :loading="loadinWorkLicenseInfo"
                @click="driverCertification"
                >保存资料</Button
              >
            </div>
            <Row> </Row>
          </TabPane>
        </Tabs>
        <div class="demo-drawer-footer-drivle">
          <div style="display: flex; justify-content: space-between">
            <div style="display: flex">
              <div></div>
              <div
                v-if="form.completeCertificates == 1"
                class="popover-Tagdrverr"
              ></div>
              <div class="popover-Tagdrverr" v-else></div>
            </div>
            <div>
              <Button type="primary" @click="adoptDriverCertificateInformation"
                >审核通过</Button
              >
              &nbsp;
              <Button type="error" @click="repulseDriverCertificateInformation"
                >审核不通过</Button
              >
            </div>
          </div>
        </div>
        <Spin size="large" fix v-if="spinShow"></Spin>
      </div>
    </Drawer>
    <!-- 审核不审核通过 -->
    <Modal v-model="auditFailedModal" title="审核不通过">
      <span style="font-size: 15px">
        {{ confirmRejection }}
      </span>
      <Input
        style="margin-top: 10px"
        v-model="AuditFailedInput"
        type="textarea"
        :rows="4"
        placeholder="请输入审核不通过原因"
      />
      <div slot="footer">
        <Button @click="auditFailedModal = false">取消</Button>
        <Button
          :loading="loadingbut"
          type="primary"
          @click="auditRejectDetermine"
          >确定</Button
        >
      </div>
    </Modal>
    <Modal v-model="numberDrivers" title="驾驶员" width="1300">
      <Form
        ref="fromDrivers"
        :model="fromDrivers"
        inline
        :label-width="70"
        class="search-form"
      >
        <FormItem label="驾驶员姓名" prop="driverName">
          <Input
            type="text"
            v-model="fromDrivers.driverName"
            placeholder="请输入驾驶员姓名"
            clearable
            style="width: 180px"
          />
        </FormItem>
        <FormItem label="手机号码">
          <Input
            type="text"
            v-model="fromDrivers.driverPhone"
            placeholder="请输入手机号码"
            clearable
            style="width: 180px"
          />
        </FormItem>
        <FormItem label="车牌号" prop="vehicleNum">
          <Input
            type="text"
            v-model="fromDrivers.vehicleNum"
            placeholder="请输入车牌号"
            clearable
            style="width: 180px"
          />
        </FormItem>
        <FormItem label="认证状态">
          <Select v-model="fromDrivers.driverUserStatus" style="width: 180px">
            <Option value="">全部</Option>
            <Option value="0">未认证</Option>
            <Option value="1">已认证</Option>
            <Option value="2">待审核</Option>
            <Option value="3">已过期</Option>
          </Select>
        </FormItem>

        <span style="margin-left: 35px" class="br">
          <Button
            @click="getPcJoinDriverVoList"
            type="primary"
            icon="ios-search"
            >搜索</Button
          >
          <Button @click="driversHandleReset">重置</Button>
        </span>
      </Form>
      <Row>
        <Table
          :loading="loading1"
          border
          :columns="columnDrivers"
          :data="getPcJoinDriverVoData"
          ref="table"
          sortable="custom"
        >
        </Table>
      </Row>
      <div style="width: 100%; height: 20px"></div>
      <Row type="flex" justify="end" class="page">
        <Page
          transfer
          :current="fromDrivers.pageNumber"
          :total="fromDrivers.total"
          :page-size="fromDrivers.pageSize"
          @on-change="changePageDrivers"
          @on-page-size-change="changePageSizeDrivers"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
      <div slot="footer">
        <Button @click="auditFailedModal = false">取消</Button>
        <Button
          :loading="loadingbut"
          type="primary"
          @click="auditRejectDetermine"
          >确定</Button
        >
      </div>
    </Modal>
    <!--  -->
    <Modal v-model="numberVehicles" title="车辆" width="1300">
      <Form
        ref="fromVehicles"
        :model="fromVehicles"
        inline
        :label-width="70"
        class="search-form"
      >
        <FormItem label="车牌号" prop="vehicleNum">
          <Input
            type="text"
            v-model="fromVehicles.vehicleNum"
            placeholder="请输入车牌号"
            clearable
            style="width: 180px"
          />
        </FormItem>

        <FormItem label="驾驶驾驶员">
          <Input
            type="text"
            v-model="fromVehicles.driverName"
            placeholder="请输入驾驶驾驶员"
            clearable
            style="width: 180px"
          />
        </FormItem>
        <FormItem label="认证状态">
          <Select v-model="fromVehicles.registStatus" style="width: 180px">
            <Option value="">全部</Option>
            <Option value="0">未认证</Option>
            <Option value="1">已认证</Option>
            <Option value="2">待审核</Option>
            <Option value="3">已过期</Option>
          </Select>
        </FormItem>
        <span style="margin-left: 35px" class="br">
          <Button @click="getPcTransportData" type="primary" icon="ios-search"
            >搜索</Button
          >
          <Button @click="vehicleHandleReset">重置</Button>
        </span>
      </Form>
      <Row>
        <Table
          :loading="loading1"
          border
          :columns="columnVehicles"
          :data="getPcTransportVehicleListData"
          ref="table"
          sortable="custom"
        >
        </Table>
      </Row>
      <div style="width: 100%; height: 20px"></div>
      <Row type="flex" justify="end" class="page">
        <Page
          transfer
          :current="fromVehicles.pageNumber"
          :total="fromVehicles.total"
          :page-size="fromVehicles.pageSize"
          @on-change="changeSortVehicles"
          @on-page-size-change="changeSelectVehicles"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
      <div slot="footer">
        <Button @click="auditFailedModal = false">取消</Button>
        <Button
          :loading="loadingbut"
          type="primary"
          @click="auditRejectDetermine"
          >确定</Button
        >
      </div>
    </Modal>
    <!-- 驾驶员详情   -->
    <DriverDetails
      @DriverDetaEnd="DriverDetaEnd"
      :BidderdUserId="BidderdUserId"
      :driverModalue="this.driverModalue"
    >
    </DriverDetails>

    <!-- 车辆详情 -->
    <VehicleDetails
      @VehicleDetailsEnd="VehicleDetailsEnd"
      :VehicleDetailsId="VehicleDetailsId"
      :VehicleDetailsModalue="this.VehicleDetailsModalue"
    >
    </VehicleDetails>
    <!-- <addDriver
      :data="form"
      :type="showType"
      v-model="showUser"
      @on-submit="getDataList"
    /> -->
  </div>
</template>
<script>
// 根据你的实际请求api.js位置路径修改
import VehicleDetails from "@/views/componentsonn_source_goods/VehicleDetails";
import DriverDetails from "@/views/componentsonn_source_goods/DriverDetails";
// 根据你的实际添加编辑组件位置路径修改
import { disableUser, enableUser, addDownloadRecord } from "@/api/index";
import excel from "@/libs/excel";
// 新增驾驶员
// import addDriver from "./addDriver.vue";
////////////////////////////////////////////////////////
import {
  getDriverVoList,
  saveDriverInfo,
  getCarrierDriverVo,
  getIdCarDInfo,
  getDriverLicenseInfo,
  getWorkLicenseInfo,
  getOwnerUserInfo,
  getIndividualUserInfo,
  saveOwnerInfo, //保存车主信息
  saveIndividualInfo, //保存个体户信息
} from "@/api/user";

import {
  uploadIdCardPic,
  uploadVehiclePic,
  upLoadDriverLicense,
  upLoadWorkLicense,
  uploadHeadPortrait,
  uploadPic,
  upLoadCompanyLicense,
} from "@/api/index";
import { getStore } from "@/libs/storage";
import * as imageConversion from "image-conversion";
// 根据你的实际请求api.js位置路径修改
import {
  userLoginistStatus,
  getPcJoinDriverVo,
  getPcTransportVehicleList,
} from "@/api/user";
export default {
  name: "driverInfo",
  data() {
    return {
      BidderdUserId: "", //报价人Id
      driverModalue: false, //驾驶员详情弹框
      VehicleDetailsId: "", //车辆id
      VehicleDetailsModalue: false, //车辆详情弹框
      loadRealInspection: false,

      getPcJoinDriverVoData: [],
      loading1: false,
      vehiclUserId: "",
      driverUserId: "",
      numberDrivers: false,
      numberVehicles: false,
      getPcTransportVehicleListData: [],
      fromDrivers: {
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        total: 0,
        registStatus: "2",
        vehicleNum: "",
        driverName: "",
      },
      vehicleLength: [],
      vehicleType: [],
      fromVehicles: {
        registStatus: "",
        vehicleType: "",
        vehicleLength: "",
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        total: 0,
      },

      authenticationTilel: "",
      upLoadCompanyLicense: upLoadCompanyLicense,
      driverShowImg: true,
      customerTypess: "",

      customType: false,
      customerType: "车主",
      customerTypes: "",
      uploadPic: uploadPic,

      uploadHeadPortrait: uploadHeadPortrait,
      auditFailedModal: false, // 审核不通过
      confirmRejection: "",
      AuditFailedInput: "",
      loadingbut: false,

      spinShow: false,
      //新增驾驶员
      showUser: false,
      showType: "0",

      openSearch: true, // 显示搜索
      openTip: true, // 显示提示
      showType: "0", // 添加或编辑标识
      showDrawer: false, // 显示添加编辑抽屉
      loading: true, // 表单加载状态
      drop: false,
      dropDownContent: "展开",
      dropDownIcon: "ios-arrow-down",
      searchForm: {
        // 搜索框初始化对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        sort: "createTime", // 默认排序字段
        order: "desc", // 默认排序方式
        name: "",
        vehicleNum: "",
        mobile: "",
        registStatus: "2", //默认查全部
        carOwnername: "",
        userType: "",
      },
      form: {},
      exportModalVisible: false, // 自定义导出显示
      exportData: [], // 多选数据
      exportTitle: "确认导出",
      filename: "驾驶员审核列表",
      loadingExport: true, // 导出加载状态\
      chooseColumns: [],
      exportRemarks: "",
      columns: [
        {
          type: "selection",
          minWidth: 60,
          align: "center",
        },
        {
          title: "#",
          type: "index",
          minWidth: 60,
        },
        {
          title: "头像",
          key: "avatar",
          width: 80,
          // align: "center",
          render: (h, params) => {
            let avatarUrl = "";
            if (
              params.row.avatar ==
              "https://ooo.0o0.ooo/2019/04/28/5cc5a71a6e3b6.png"
            ) {
              avatarUrl = "https://ooo.0o0.ooo/2019/04/28/5cc5a71a6e3b6.png";
            } else if (params.row.avatar == "" || params.row.avatar == null) {
              avatarUrl = "https://ooo.0o0.ooo/2019/04/28/5cc5a71a6e3b6.png";
            } else {
              avatarUrl = this.$baseUrl + params.row.avatar;
            }
            return h("Avatar", {
              props: {
                src: avatarUrl,
              },
            });
          },
        },
        {
          title: "登录账号",
          key: "mobile",
          minWidth: 125,
          sortable: false,
        },
        {
          title: "用户姓名",
          key: "name",
          minWidth: 100,
          sortable: false,
          // render: (h, params) => {
          //   return h("div", [
          //     h(
          //       "a",
          //       {
          //         on: {
          //           click: () => {
          //             let obj = params.row.driverInfoVo;
          //             this.BidderdDiver(params.row);
          //           },
          //         },
          //       },
          //       params.row.name
          //     ),
          //   ]);
          // },
        },

        {
          title: "性别",
          key: "sex",
          minWidth: 80,
          sortable: false,
        },
        {
          title: "年龄",
          key: "birth",
          minWidth: 80,
          sortable: false,
          render: (h, params) => {
            if (params.row.birth) {
              let year = new Date().getFullYear();
              let now = Number(params.row.birth.substring(0, 4));
              return h("div", year - now);
            }
          },
        },
        {
          title: "身份证号",
          key: "num",
          minWidth: 190,
          sortable: false,
        },

        {
          title: "驾驶车辆",
          key: "vehicleNum",
          minWidth: 120,
          render: (h, params) => {
            if (params.row.vehicleNum == "" || params.row.vehicleNum == null) {
              return h(
                "div",
                {
                  style: {
                    color: "#D0C4DE",
                  },
                },
                "未绑定"
              );
            } else {
              return h("div", [h("span", params.row.vehicleNum)]);
            }
          },
        },

        {
          title: "更新时间",
          key: "updateTime",
          minWidth: 180,
          sortable: false,
        },
        {
          title: "创建时间",
          key: "createTime",
          minWidth: 180,
          sortable: false,
        },
        {
          title: "认证状态",
          key: "registStatus",
          minWidth: 100,
          align: "center",
          fixed: "right",
          render: (h, params) => {
            let colorStatus = "";
            let titleText = "";
            if (params.row.registStatus == 0) {
              colorStatus = "error";
              titleText = "未认证";
            } else if (params.row.registStatus == 1) {
              colorStatus = "success";
              titleText = "已认证";
            } else if (params.row.registStatus == 2) {
              colorStatus = "processing";
              titleText = "待审核";
            } else if (params.row.registStatus == 3) {
              colorStatus = "error";
              titleText = "已过期";
            }
            return h("div", [
              h("Badge", {
                props: {
                  status: colorStatus,
                  text: titleText,
                },
              }),
            ]);
          },
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          fixed: "right",
          width: 80,
          render: (h, params) => {
            return h("div", [
              h(
                "a",
                {
                  on: {
                    click: () => {
                      this.edit(params.row);
                    },
                  },
                },
                "审核"
              ),
            ]);
          },
        },
      ],

      data: [], // 表单数据
      pageNumber: 1, // 当前页数
      pageSize: 10, // 页面大小
      total: 0, // 表单数据总数
      ////////////////////////////////////////////////////////////////////////////////
      driverVisible: false,
      load: 0, // 动态显示进度条

      loadinIdcardInfo: false,
      loadinDriverInfo: false,
      loadinWorkLicenseInfo: false,

      uploadIdCardPic: uploadIdCardPic,
      uploadVehiclePic: uploadVehiclePic,
      upLoadDriverLicense: upLoadDriverLicense,
      upLoadWorkLicense: upLoadWorkLicense,
      visible: this.value,
      imgVisible: false,

      header: {
        accessToken: getStore("accessToken"),
      },
      accessToken: getStore("accessToken"),
      title: "",
      driverTabPane: "name1",
      driverData: {
        userId: "", // 用户id
        num: "", // 身份证号
        name: "", // 姓名
        address: "", // 地址
        birth: "", // 生日
        sex: "", // 性别
        nationality: "", // 民族
        issue: "", // 签发机关
        startDate: "", // 身份证起始日期
        endDate: "", // 身份证结束日期
        idCardFontPicFileId: "", // 身份证前置照片地址
        idCardBackPicFileId: "", // 身份证后置照片地址
        holdIdCardFileId: "", // 手持身份证照片ID
        driverPhotosFileId: "", // 驾驶员照片ID

        licenseName: "", // 驾驶证 --- 姓名
        licenseNum: "", // 驾驶证 --- 驾驶证号
        driverType: "", // 驾驶证准驾车型
        licenseStartDate: "", // 驾驶证有效期开始时间
        issuingOrganizations: "", // 驾驶证 --- 发证机关
        licenseEndDate: "", // 驾驶证有效期时长
        issueDate: "", // 驾驶证 --- 初次领证日期
        yearlyInspectionDate: "", //驾驶证 --- 年检日期
        addr: "", // 驾驶证 --- 地址
        licenseSex: "", // 驾驶证 --- 性别
        archiveNo: "", // 驾驶证 --- 档案编号
        driverFontPicFileID: "", // 驾照证正面地址
        driverBackPicFileID: "", // 驾照证反面地址

        workLicenseNo: "", // 从业资格证号
        workLicenseExpiryTime: "", // 资格证到期时间
        workLicensePicFileId: "", // 从业资格证文件id
        roadPermitNo: "", // 道路运输经营许可证号
        roadPermitNoDate: "", // 道路运输经营许可证有效期
        roadOperPermitPicFileId: "", // 道路经营许可证
        affiliatedCompanyName: "", // 挂靠运输公司名称
        affiliatedCompanyCode: "", // 统一社会信用代码

        phone: "", // 手机号
        cardNumber: "", // 银行卡号
        cardName: "", // 银行卡名
        cardCode: "", // 银行编码
        bankFileId: "", // 银行卡照片

        ownerNum: "", // 身份证号
        ownerName: "", // 姓名
        ownerAddress: "", // 地址
        ownerBirth: "", // 生日
        ownerSex: "", // 性别
        ownerNationality: "", // 民族
        ownerStartDate: "", // 身份证起始日期
        ownerEndDate: "", // 身份证结束日期
        ownerIssue: "", // 签发机关
        ownerIdCardFontPicFileId: "", // 身份证前置照片地址
        ownerIdCardBackPicFileId: "", // 身份证后置照片地址
        ownerHoldIdCardFileId: "", // 手持身份证照片ID
        businessLicenseFileId: "", //营业执照
        contactPhone: "",
      },
      RealAuthentication: {
        name: [
          {
            required: true,
            message: "请输入姓名",
            trigger: "blur",
          },
        ],
        num: [
          {
            required: true,
            message: "请输入身份证号码",
            trigger: "blur",
          },
        ],
        birth: [
          {
            required: true,
            message: "请输入出生日期",
            trigger: "blur",
          },
        ],
        address: [
          {
            required: true,
            message: "请输入家庭地址",
            trigger: "blur",
          },
        ],
        sex: [
          {
            required: true,
            message: "请输入性别",
            trigger: "blur",
          },
        ],
        startDate: [
          {
            required: true,
            message: "请输入开始时间",
            trigger: "blur",
          },
        ],
        endDate: [
          {
            required: true,
            message: "请输入有效截至时间",
            trigger: "blur",
          },
        ],
        contactPhone: [
          {
            required: true,
            message: "请输入联系人电话",
            trigger: "blur",
          },
        ],
      },
      // 驾驶证
      driverData2: {
        licenseName: "",
        licenseNum: "",
        driverType: "",
        contactPhone: "",
        issueDate: "",
        licenseStartDate: "",
        licenseEndDate: "",
        issuingOrganizations: "",
        yearlyInspectionDate: "",
      },
      RealAuthentication2: {
        licenseName: [
          {
            required: true,
            message: "请输入姓名",
            trigger: "blur",
          },
        ],
        licenseNum: [
          {
            required: true,
            message: "请输入驾驶证号",
            trigger: "blur",
          },
        ],
        driverType: [
          {
            required: true,
            message: "请输入准驾车型",
            trigger: "blur",
          },
        ],

        issueDate: [
          {
            required: true,
            message: "请输入领证日期",
            trigger: "blur",
          },
        ],

        licenseStartDate: [
          {
            required: true,
            message: "请输入开始时间",
            trigger: "blur",
          },
        ],

        licenseEndDate: [
          {
            required: true,
            message: "请输入截至时间",
            trigger: "blur",
          },
        ],
        issuingOrganizations: [
          {
            required: true,
            message: "请输入发证机关",
            trigger: "blur",
          },
        ],
      },
      driverRegistStatus: "",
      submitLoading: false,
      maxHeight: 510,
      activeSrc: "",
      idCardFontPicFileUrl: "", //驾驶员身份证正面
      idCardBackPicFileUrl: "", //驾驶员身份证背面
      personalIDCardUrl: "", //驾驶员手持身份证
      FrontIDCardTrue: false, // 驾驶员身份证正面
      ReverseSideIDCardTrue: false, // 驾驶员身份证背面
      progressCardBack: false, //驾驶员手持身份证进度条

      driverPhotosId: "", //驾驶员照片
      driverPhotosIdProgress: false, //驾驶员照片进度条

      driverFontPicFileUrl: "", //驾照主页
      driverBackPicFileUrl: "", //驾照副页
      DriverLicenseTrue: false, // 驾照主页关闭进度条
      DriverLicenPageTrue: false, // 驾照副页关闭进度条

      QualificationTrue: false, // 从业资格证关闭进度条
      workLicensePicFileUrl: "", //从业资格证

      qualificationTrueSidePage: false, // 从业资格证关闭进度条-副页
      workLicensePicFileUrlSidePage: "", //诚信考核情况

      BusineLicensetrue: false, //道路运输经营许可证
      xukezhengPicFileUrl: "", //道路运输经营许可证

      frontHandHeldIDCard: "", //经营者手持身份证
      frontSideIDCardShow: false, //经营者身份证背面进度条
      affiliationAgreement: "", //营业执照
    };
  },
  components: {
    VehicleDetails,
    // addDriver,
    DriverDetails,
  },
  methods: {
    //驾照主页
    driverFontHandleSuccess(res) {
      this.spinShow = true;
      if (res.code == 500) {
        setInterval(() => {
          this.spinShow = false;
        }, 1000);
        this.$Message.error(res.message);
        return;
      } else if (res.code == 200) {
        setInterval(() => {
          this.spinShow = false;
        }, 1000);
        this.$Message.success("上传成功");
      }

      this.driverData2.licenseName = res.result.name;
      this.driverData2.licenseNum = res.result.num;
      this.driverData.licenseSex = res.result.sex;
      this.driverData2.driverType = res.result.driverType;
      this.driverData2.licenseStartDate = res.result.startDate;

      if (
        res.result.issuingOrganizations != "" &&
        res.result.issuingOrganizations != "null" && //issuingOrganizations
        res.result.issuingOrganizations != null
      ) {
        this.driverData2.issuingOrganizations = res.result.issuingOrganizations;
      } else {
        this.driverData2.issuingOrganizations = "";
      }

      //判断长期+99年
      if (res.result.endDate == "长期") {
        let dateNew = Number(res.result.startDate) + Number(990000);
        this.driverData2.licenseEndDate = dateNew + "";
      } else {
        this.driverData2.licenseEndDate = res.result.endDate;
      }

      this.driverData2.issueDate = res.result.issueDate;
      this.driverData.addr = res.result.addr;
      this.driverData.driverFontPicFileID = res.result.filepath;
      if (this.driverData.driverFontPicFileID != null) {
        this.driverFontPicFileUrl = this.$baseUrl + res.result.filepath;
      }
    },
    // 从业资格证
    workLicenesSuccess(res) {
      this.spinShow = true;
      if (res.code == 500) {
        this.$Message.error(res.message);
        setInterval(() => {
          this.spinShow = false;
        }, 1000);
        return;
      } else if (res.code == 200) {
        setInterval(() => {
          this.spinShow = false;
        }, 1000);
        this.$Message.success("上传成功");
      }
      this.driverData.workLicensePicFileId = res.result.filepath;
      if (this.driverData.workLicensePicFileId != null) {
        this.workLicensePicFileUrl = this.$baseUrl + res.result.filepath;
      } else {
        this.$Message.error(res.message);
      }
    },
    // 获取驾驶员列表
    getPcJoinDriverVoList() {
      this.loading1 = true;
      this.fromDrivers.userId = this.driverUserId;
      getPcJoinDriverVo(this.fromDrivers).then((res) => {
        this.loading1 = false;
        if (res.result.records.length > 0) {
          this.getPcJoinDriverVoData = res.result.records;
          this.fromDrivers.total = res.result.total;
        } else {
          this.getPcJoinDriverVoData = [];
        }
      });
    },
    // 车辆列表重置
    driversHandleReset() {
      this.fromDrivers.pageNumber = 1;
      this.fromDrivers.pageSize = 10;
      this.fromDrivers.driverName = "";
      this.fromDrivers.driverPhone = "";
      this.fromDrivers.vehicleNum = "";
      this.fromDrivers.driverUserStatus = "";
      this.getPcJoinDriverVoList();
    },
    // 获取车辆列表
    getPcTransportData() {
      this.fromVehicles.userId = this.vehiclUserId;
      this.loading1 = true;
      getPcTransportVehicleList(this.fromVehicles).then((res) => {
        this.loading1 = false;
        if (res.result.records.length > 0) {
          this.getPcTransportVehicleListData = res.result.records;
          this.fromVehicles.total = res.result.total;
        } else {
          this.getPcTransportVehicleListData = [];
        }
      });
    },
    // 车辆列表重置
    vehicleHandleReset() {
      this.fromVehicles.pageNumber = 1;
      this.fromVehicles.pageSize = 10;
      this.fromVehicles.vehicleNum = "";
      this.fromVehicles.driverName = "";
      this.fromVehicles.registStatus = "";
      this.getPcTransportData();
    },

    // 驾驶员
    driverDataIssueDate(val) {
      this.driverData2.issueDate = val;
      this.driverData.issueDate = val;
    },

    BidderdDiver(row) {
      this.BidderdUserId = row.driverUserId;
      this.driverModalue = true;
    },
    DriverDetaEnd(val) {
      this.driverModalue = val;
      this.BidderdUserId = "";
    },
    driverDataBirth(val) {
      this.driverData.birth = val;
    },
    driverDataStartDate(val) {
      this.driverData.startDate = val;
    },
    driverDataEndDate(val) {
      this.driverData.endDate = val;
    },
    driverDataOwnerEndDate(val) {
      this.driverData.ownerEndDate = val;
    },
    // 诚信考核有效期
    workLicenseAssessmentData(val) {
      this.driverData3.sincerityExpiryTime = val;
      this.driverData.sincerityExpiryTime = val;
    },
    // 新增驾驶员
    newDrier() {
      this.showType = "2";
      this.showUser = true;
    },
    init() {
      this.getDataList();
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
      this.clearSelectAll();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getDataList();
    },
    handleReset() {
      // this.$refs.searchForm.resetFields();
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.searchForm.vehicleNum = "";
      this.searchForm.registStatus = "2";
      this.searchForm.mobile = "";
      this.searchForm.name = "";
      this.searchForm.carOwnername = "";
      this.searchForm.userType = "";
      // 重新加载数据
      this.getDataList();
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order === "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    dropDown() {
      if (this.drop) {
        this.dropDownContent = "展开";
        this.dropDownIcon = "ios-arrow-down";
      } else {
        this.dropDownContent = "收起";
        this.dropDownIcon = "ios-arrow-up";
      }
      this.drop = !this.drop;
    },
    clearSelectAll() {
      this.$refs.table.selectAll(false);
    },
    getDataList() {
      this.loading = true;
      getDriverVoList(this.searchForm).then((res) => {
        this.loading = false;
        if (res.success) {
          this.data = res.result.records;
          this.total = res.result.total;
          this.data.forEach((item) => {
            if (item.informationTips != "" && item.informationTips != null) {
              if (
                item.informationTips.charAt(item.informationTips.length - 1) ==
                ","
              ) {
                item.informationTips = item.informationTips.substring(
                  0,
                  item.informationTips.lastIndexOf(",")
                );
              }
              item.informationTipsVehicle = item.informationTips.split(",");
            } else {
              item.informationTipsVehicle = item.informationTips;
            }
          });
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
        }
      });
    },
    add() {
      this.showType = "2";
      this.showDrawer = true;
    },
    edit(v) {
      // this.driverShowImg = false;
      this.driverTabPane = "name1";
      this.spinShow = true;
      this.customerType = "车主";
      this.driverRegistStatus = v.registStatus;
      this.idCardFontPicFileUrl = ""; //身份证正面
      this.idCardBackPicFileUrl = ""; //身份证返面
      this.driverFontPicFileUrl = ""; //驾照主页
      this.workLicensePicFileUrl = ""; //从业资格证

      this.workLicensePicFileUrlSidePage = "";

      this.$refs.driverData.resetFields();
      this.$refs.driverData2.resetFields();
      // 转换null为""
      for (let attr in v) {
        if (v[attr] == null) {
          v[attr] = "";
        }
      }
      let str = JSON.stringify(v);
      let data = JSON.parse(str);
      this.form = data;
      this.showType = "1";
      if (
        this.form.informationTips != "" &&
        this.form.informationTips != null
      ) {
        if (
          this.form.informationTips.charAt(
            this.form.informationTips.length - 1
          ) == ","
        ) {
          this.form.informationTips = this.form.informationTips.substring(
            0,
            this.form.informationTips.lastIndexOf(",")
          );
        }
        this.form.informationTipsVehicle = this.form.informationTips.split(",");
      } else {
        this.form.informationTipsVehicle = this.form.informationTips;
      }
      this.customerTypes = v.customerType;
      //
      this.realNameAuthentication();

      this.authenticationTilel = "驾驶员认证信息";
      this.driverShow = true;

      this.driverVisible = true;
      setInterval(() => {
        this.spinShow = false;
      }, 1000);
    },
    // 图片格式化
    imgFormat(val) {
      let img = "";
      if (val) {
        img = this.$baseUrl + val;
      }
      return img;
    },
    driverTabs(val) {
      if (this.driverTabPane == "name1") {
        this.spinShow = true;
        // // 实名认证
        this.realNameAuthentication();
        setTimeout(() => {
          this.spinShow = false;
        }, 1000);
      } else if (this.driverTabPane == "name2") {
        this.spinShow = true;
        // //  驾照认证
        this.DriverLicenseCertification();
        setInterval(() => {
          this.spinShow = false;
        }, 1000);
      }
    },
    //  驾照认证
    DriverLicenseCertification() {
      getDriverLicenseInfo({ userId: this.form.userId }).then((res) => {
        if (res.success) {
          if (res.result.id != null) {
            this.driverData2.licenseName = res.result.name;
            this.driverData2.licenseNum = res.result.num;
            this.driverData2.driverType = res.result.driverType;
            this.driverData2.issuingOrganizations =
              res.result.issuingOrganizations;
            this.driverData.addr = res.result.addr;
            this.driverData2.licenseSex = res.result.licenseSex;
            this.driverData.archiveNo = res.result.archiveNo;

            this.driverData2.issueDate = res.result.issueDate;
            this.driverData2.licenseStartDate = res.result.startDate;

            this.driverData2.yearlyInspectionDate =
              res.result.yearlyInspectionDate;
            this.driverData2.licenseEndDate = res.result.endDate;
            if (
              res.result.issuingOrganizations != "" &&
              res.result.issuingOrganizations != "null" &&
              res.result.issuingOrganizations != null
            ) {
              this.driverData2.issuingOrganizations =
                res.result.issuingOrganizations;
            } else {
              this.driverData2.issuingOrganizations = "";
            }
            //
            if (res.result.driverFontPicFileID != null) {
              this.driverData.driverFontPicFileID =
                res.result.driverFontPicFileID;

              this.driverFontPicFileUrl = this.imgFormat(
                res.result.driverFontPicFileID
              );
            }
            // workLicensePicFileId
            if (res.result.workLicensePicFileId != null) {
              this.driverData.workLicensePicFileId =
                res.result.workLicensePicFileId;

              this.workLicensePicFileUrl = this.imgFormat(
                res.result.workLicensePicFileId
              );
            }
          }
        } else {
          this.$Message.error(res.message);
        }
        setInterval(() => {
          this.spinShow = false;
        }, 1000);
      });
    },
    // 点击禁用
    frozen(v) {
      this.$Modal.confirm({
        title: "确认禁用",
        content: "您确认要禁用 " + v.name + " 用户吗?",
        loading: true,
        onOk: () => {
          disableUser(v.userId).then((res) => {
            this.$Modal.remove();
            if (res.success) {
              this.$Message.success("操作成功");
              this.getDataList();
            } else {
              this.$Message.error(res.message);
            }
          });
        },
      });
    },
    //启用
    Enable(v) {
      this.$Modal.confirm({
        title: "确认启用",
        content: "您确认要启用 " + v.name + " 用户吗?",
        loading: true,
        onOk: () => {
          enableUser(v.userId).then((res) => {
            this.$Modal.remove();
            if (res.success) {
              this.$Message.success("操作成功");
              this.getDataList();
            } else {
              this.$Message.error(res.message);
            }
          });
        },
      });
    },
    // 查看车辆详细
    LookVehicleInfo(row) {
      this.VehicleDetailsModalue = true;
      this.VehicleDetailsId = row.vehicleId;
    },
    //车辆详细信息关闭
    VehicleDetailsEnd(val) {
      this.VehicleDetailsModalue = val;
      this.VehicleDetailsId = "";
    },
    //////////////////////////////////////////////////////////////////////////
    // 查看图片
    showPic(v) {
      let image = new Image();
      image.src = v;
      let viewer = new Viewer(image, {
        hidden: function () {
          viewer.destroy();
        },
      });
      viewer.show();
    },

    // 身份证正面
    FrontIDCard(event, file, fileList) {
      this.progressAll(event, 1);
    },
    // 身份证背面
    ReverseSideIDCard(event, file, fileList) {
      this.progressAll(event, 2);
    },
    // 驾照主页
    DriverLicense(event, file, fileList) {
      this.progressAll(event, 3);
    },
    // 驾照主页
    DriverLicenPage(event, file, fileList) {
      this.progressAll(event, 4);
    },
    // 从业资格证
    QualificationCertificate(event, file, fileList) {
      this.progressAll(event, 5);
    },
    // 诚信考核情况
    qualificationSidePage(event, file, fileList) {
      this.progressAll(event, 18);
    },

    //进度条
    progressAll(data, num) {
      if (num == 1) {
        //身份证正面进度条
        this.FrontIDCardTrue = true; // 显示进度条
      } else if (num == 2) {
        //身份证背面进度条
        this.ReverseSideIDCardTrue = true; // 显示进度条
      } else if (num == 3) {
        this.DriverLicenseTrue = true;
      } else if (num == 4) {
        this.DriverLicenPageTrue = true;
      } else if (num == 5) {
        this.QualificationTrue = true;
      } else if (num == 18) {
        this.qualificationTrueSidePage = true;
      }

      var CardBack = setTimeout(() => {
        this.load = parseInt(data.percent); // 动态获取文件上传进度
      }, 500); // 一秒后关闭进度条
      setTimeout(() => {
        if (this.load >= 100) {
          this.load = 100;
          setTimeout(() => {
            if (num == 1) {
              this.FrontIDCardTrue = false; // 显示进度条
            } else if (num == 2) {
              this.ReverseSideIDCardTrue = false; // 显示进度条
            } else if (num == 3) {
              this.DriverLicenseTrue = false;
            } else if (num == 4) {
              this.DriverLicenPageTrue = false;
            } else if (num == 5) {
              //身份证背面进度条
              this.QualificationTrue = false;
            } else if (num == 18) {
              this.qualificationTrueSidePage = false;
            }
          }, 1000); // 一秒后关闭进度条
          clearTimeout(CardBack);
        }
      }, 501);
    },
    // 删除图片
    handleRemove(file, num) {
      if (num == 1) {
        // 身份证正面
        this.idCardFontPicFileUrl = "";
      } else if (num == 2) {
        // 身份证背面
        this.idCardBackPicFileUrl = "";
      } else if (num == 3) {
        // 驾照主页
        this.driverFontPicFileUrl = "";
      } else if (num == 4) {
        // 驾照副页
        this.driverBackPicFileUrl = "";
      } else if (num == 5) {
        //从业资格证
        this.workLicensePicFileUrl = "";
      } else if (num == 6) {
        //诚信考核情况
        this.workLicensePicFileUrlSidePage = "";
      } else if (num == 7) {
        //个人认证身份证反面
        this.idCardFontPicFileUrl = "";
      } else if (num == 8) {
        //个人认证身份证反面
        this.idCardBackPicFileUrl = "";
      }
    },
    // 身份证正面
    cardFontHandleSuccess(res) {
      this.spinShow = true;
      if (res.code == 500) {
        this.$Message.error(res.message);
        setTimeout(() => {
          this.spinShow = false;
        }, 1000);
        return;
      } else if (res.code == 200) {
        setTimeout(() => {
          this.spinShow = false;
        }, 1000);
        this.$Message.success("上传成功");
      }
      this.driverData.name = res.result.name;
      this.driverData.num = res.result.num;
      this.driverData.birth = res.result.birth;
      this.driverData.sex = res.result.sex;
      this.driverData.nationality = res.result.nationality;
      this.driverData.address = res.result.address;
      this.driverData.idCardFontPicFileId = res.result.filepath;

      this.driverData.workLicenseNo = res.result.num;

      if (this.driverData.idCardFontPicFileId != null) {
        this.idCardFontPicFileUrl = this.$baseUrl + res.result.filepath;
      }
    },
    // 身份证背面
    cardBackHandleSuccess(res) {
      this.spinShow = true;
      if (res.code == 500) {
        this.$Message.error(res.message);
        setTimeout(() => {
          this.spinShow = false;
        }, 1000);
        return;
      } else if (res.code == 200) {
        setTimeout(() => {
          this.spinShow = false;
        }, 1000);
        this.$Message.success("上传成功");
      }
      this.driverData.startDate = res.result.startDate;

      //判断长期+99年
      if (res.result.endDate == "长期") {
        let dateNew = Number(res.result.startDate) + Number(990000);
        this.driverData.endDate = dateNew + "";
      } else {
        this.driverData.endDate = res.result.endDate;
      }

      this.driverData.issue = res.result.issue;

      this.driverData.idCardBackPicFileId = res.result.filepath;
      if (this.driverData.idCardBackPicFileId != null) {
        this.idCardBackPicFileUrl = this.$baseUrl + res.result.filepath;
      }
    },

    // 驾驶员证件信息通过
    adoptDriverCertificateInformation() {
      this.$refs.driverData.validate((valid) => {
        if (valid) {
          this.$Modal.confirm({
            title: "确认通过",
            // 记得确认修改此处
            content: "确认通过 " + this.form.name + " 用户的驾驶员认证信息吗？",
            loading: true,
            onOk: () => {
              userLoginistStatus({
                userId: this.form.userId,
                registState: 1,
              }).then((res) => {
                this.$Modal.remove();
                if (res.success) {
                  this.driverVisible = false;
                  this.$Message.success("审核通过");
                  this.getDataList();
                }
              });
            },
          });
        } else {
          return this.$Message.warning("驾驶证填写不完整");
        }
      });
    },
    // 驾驶员证件信息驳回
    repulseDriverCertificateInformation() {
      this.auditFailedModal = true;
      this.AuditFailedInput = "";
      this.confirmRejection =
        "确认拒绝 " + this.form.name + " 用户的驾驶员认证信息吗？";
    },

    // 审核不通过
    auditRejectDetermine() {
      if (this.AuditFailedInput == "") {
        this.$Message.warning("请输入审核不通过原因");
        return false;
      }
      this.loadingbut = true;
      userLoginistStatus({
        userId: this.form.userId,
        registState: 0,
        reason: this.AuditFailedInput,
      }).then((res) => {
        this.loadingbut = false;
        if (res.success) {
          this.driverVisible = false;
          this.auditFailedModal = false;
          this.$Message.success("审核拒绝");
          this.getDataList();
        } else {
          this.$Message.error(res.message);
        }
      });
    },

    // 驾驶员认证
    driverCertification() {
      let drivern = false;
      let drivern1 = false;
      let drivern2 = false;
      this.$refs.driverData.validate((valid) => {
        drivern = false;
        if (valid) {
          if (this.idCardFontPicFileUrl == "") {
            return this.$Message.warning("请上传身份证正面");
          }
          if (this.idCardBackPicFileUrl == "") {
            return this.$Message.warning("请上传身份证背面");
          }
        } else {
          return this.$Message.warning("身份证填写不完整");
        }
        drivern = true;
      });
      this.$refs.driverData2.validate((valid) => {
        drivern1 = false;
        if (valid) {
          if (this.driverFontPicFileUrl == "") {
            return this.$Message.warning("请上传驾照主页");
          } else if (this.workLicensePicFileUrl == "") {
            return this.$Message.warning("请上从业资格证");
          }
          this.driverData.licenseName = this.driverData2.licenseName;
          this.driverData.licenseNum = this.driverData2.licenseNum;
          this.driverData.driverType = this.driverData2.driverType;

          this.driverData.issueDate = this.driverData2.issueDate;
          this.driverData.licenseStartDate = this.driverData2.licenseStartDate;
          this.driverData.licenseEndDate = this.driverData2.licenseEndDate;
          this.driverData.yearlyInspectionDate =
            this.driverData2.yearlyInspectionDate;
          this.driverData.issuingOrganizations =
            this.driverData2.issuingOrganizations;
          drivern1 = true;
        } else {
          return this.$Message.warning("驾驶证填写不完整");
        }
      });
      if (drivern && drivern1) {
        this.driverData.userId = this.form.userId;
        this.loadinWorkLicenseInfo = true;
        this.driverData.startDate = this.timeText(this.driverData.startDate);
        this.driverData.endDate = this.timeText(this.driverData.endDate);

        this.driverData.licenseStartDate = this.timeText(
          this.driverData.licenseStartDate
        );
        this.driverData.licenseEndDate = this.timeText(
          this.driverData.licenseEndDate
        );
        this.driverData.ownerEndDate = this.timeText(
          this.driverData.ownerEndDate
        );

        this.driverData.ownerStartDate = this.timeText(
          this.driverData.ownerStartDate
        );
        this.driverData.ownerEndDate = this.timeText(
          this.driverData.ownerEndDate
        );
        this.driverData.sincerityExpiryTime = this.timeText(
          this.driverData.sincerityExpiryTime
        );
        this.driverData.yearlyInspectionDate = this.timeText(
          this.driverData.yearlyInspectionDate
        );
        this.driverData.workLicenseExpiryTime = this.timeText(
          this.driverData.workLicenseExpiryTime
        );
        this.driverData.issueDate = this.timeText(this.driverData.issueDate);
        this.loadinIdcardInfo = true;
        for (let item in this.driverData) {
          if (
            this.driverData[item] == "" ||
            this.driverData[item] == null ||
            this.driverData[item] == ""
          ) {
            delete this.driverData[item];
          }
        }

        saveDriverInfo(this.driverData).then((res) => {
          this.loadinWorkLicenseInfo = false;
          this.loadinIdcardInfo = false;
          if (res.code == 200) {
            this.$Message.success("驾驶员保存资料成功");
            this.getDataList();
          } else {
            this.$Message.error(res.message);
          }
        });
      } else {
        // return this.$Message.warning("资料填写不完整");
      }
    },
    // 时间去横杠
    timeText(val) {
      let text = "";
      if (val) {
        let arr = val.split("");
        arr.forEach((item) => {
          if (item == "-") {
          } else {
            text += item;
          }
        });
      }
      return text;
    },
    //压缩图片
    beforeUpload(file) {
      return new Promise((resolve, reject) => {
        // console.log("压缩前", file); // 压缩到400KB,大于400KB的图片都会进行压缩，小于则不会
        imageConversion.compressAccurately(file, 100).then((res) => {
          res = new File([res], file.name, {
            type: res.type,
            lastModified: Date.now(),
          });
          resolve(res);
        });
      });
    },
    // 文件格式验证失败时的钩子
    handleFormatError(file) {
      this.$Message.error("图片格式错误,指定上传图片格式 jpg、jpeg、png");
    },
    // 实名认证
    realNameAuthentication() {
      getIdCarDInfo({ userId: this.form.userId }).then((res) => {
        if (res.success) {
          if (res.result.id != null) {
            this.driverData.num = res.result.num;
            this.driverData.name = res.result.name;
            this.driverData.address = res.result.address;
            this.driverData.birth = res.result.birth;
            this.driverData.sex = res.result.sex;
            this.driverData.nationality = res.result.nationality;
            this.driverData.issue = res.result.issue;
            this.driverData.startDate = res.result.startDate;
            this.driverData.endDate = res.result.endDate;
            this.driverData.contactPhone = res.result.contactPhone;
            if (res.result.idCardFontPicFileId != null) {
              this.driverData.idCardFontPicFileId =
                res.result.idCardFontPicFileId;
              this.idCardFontPicFileUrl = this.imgFormat(
                res.result.idCardFontPicFileId
              );
            }
            if (res.result.idCardBackPicFileId != null) {
              this.driverData.idCardBackPicFileId =
                res.result.idCardBackPicFileId;
              this.idCardBackPicFileUrl = this.imgFormat(
                res.result.idCardBackPicFileId
              );
            }
            // 手持身份证照片ID
            if (res.result.holdIdCardFileId != null) {
              this.driverData.holdIdCardFileId = res.result.holdIdCardFileId;
              this.personalIDCardUrl = this.imgFormat(
                res.result.holdIdCardFileId
              );
            }
            // 驾驶员照片
            if (res.result.driverPhotosFileId != null) {
              this.driverData.driverPhotosFileId =
                res.result.driverPhotosFileId;
              this.driverPhotosId = this.imgFormat(
                res.result.driverPhotosFileId
              );
            }
          }
        } else {
          this.$Message.error(res.message);
        }
      });
    },
    //  驾照认证
    getNextMonth(date) {
      var arr = date.split("-");
      var year = arr[0]; //获取当前日期的年份
      var month = arr[1]; //获取当前日期的月份
      var day = arr[2]; //获取当前日期的日
      var days = new Date(year, month, 0);
      days = days.getDate(); //获取当前日期中的月的天数
      var year2 = year;
      var month2 = parseInt(month) + 1;
      if (month2 == 13) {
        year2 = parseInt(year2) + 1;
        month2 = 1;
      }
      var day2 = day;
      var days2 = new Date(year2, month2, 0);
      days2 = days2.getDate();
      if (day2 > days2) {
        day2 = days2;
      }
      if (month2 < 10) {
        month2 = "0" + month2;
      }
      var t2 = year2 + "-" + month2 + "-" + day2;

      this.driverData3.workLicenseExpiryTime = t2;
      this.driverData.workLicenseExpiryTime = t2;
    },
    newTiem() {
      var date = new Date();
      var seperator1 = "-";
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var strDate = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      var currentdate = year + seperator1 + month + seperator1 + strDate;

      this.getNextMonth(currentdate);
    },
  },
  mounted() {
    this.init();
    // this.newTiem();
    if (localStorage.getItem("jurisdictionCargo") == "ROLE_CargOwner") {
      this.columns = this.columns.filter((col) => col.key !== "action");
    } else {
      this.columns = this.columns;
    }
  },
};
</script>
<style lang="less">
// 建议引入通用样式 具体路径自行修改 可删除下面样式代码
// @import "../../../styles/table-common.less";
.popover-Tagdrverr {
  padding-top: 6px;
}
.search {
  .operation {
    margin-bottom: 2vh;
  }
  .select-count {
    font-weight: 600;
    color: #40a9ff;
  }
  .select-clear {
    margin-left: 10px;
  }
  .page {
    margin-top: 2vh;
  }
  .drop-down {
    margin-left: 5px;
  }
}
.demo-upload-list-driver {
  display: inline-block;
  width: 150px;
  height: 90px;
  text-align: center;
  line-height: 60px;
  border: 1px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  margin-right: 4px;
}
.demo-upload-list-driver img {
  width: 148px !important;
  height: 88.2px !important;
}
.demo-upload-list-driver-cover {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
}
.demo-upload-list-driver:hover .demo-upload-list-driver-cover {
  display: block;
}
.demo-upload-list-driver-cover i {
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  margin: 0 2px;
  line-height: 90px;
}
.demo-drawer-footer-drivle {
  width: 100%;
  position: absolute;
  bottom: 0;
  left: 0;
  padding: 10px 16px;
  text-align: right;
  background-color: #f5f5f5;
  border: 1px solid #cdcdcd;
}
.check_font {
  font-size: 12px;
  font-weight: 600;
}
.demo-uploadcss-drivre {
  margin-top: -13px;
  width: 150px;
  height: 5px;
}

.check {
  &::before {
    content: "*";
    display: inline-block;
    margin-right: 2px;
    line-height: 1;
    font-family: SimSun;
    font-size: 14px;
    color: #ed4014;
  }
}
.table table {
  // table-layout: auto;
  width: 100% !important;
}
</style>